package com.jacen.fzxs.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.jacen.fzxs.dao.IWorkDao;
import com.jacen.fzxs.entity.WorkEntity;
import com.jacen.fzxs.util.SqlCondition;

@Repository
public class WorkDao extends BaseDao<WorkEntity> implements IWorkDao {

	@Override
	public List<WorkEntity> getWorkByPosition(int position) {
		String sql = "select * from %s t where t.status = %s and t.position = %s";
		sql = String.format(sql,tableName, WorkEntity.Status.START,position);
		return executeForList(sql);
	}

	@Override
	public List<WorkEntity> getPage(int beginRow, int endRow, Map<String, String> params) {
		SqlCondition cond = getPageCondition(params);
		String sql = "SELECT * from %s  where 1=1 %s ";
		sql = String.format(sql,tableName, cond.getCondition());
		sql = SqlCondition.pageSql(sql, beginRow, endRow);
		return executeForList(sql, cond.getParams().toArray());
	}

	@Override
	public int getCount(Map<String, ? extends Object> params) {
		SqlCondition cond = getPageCondition(params);
		String sql = "select count(1) from %s where 1=1 %s";
		sql = String.format(sql,tableName, cond.getCondition());
		return Long.valueOf(executeForLong(sql, cond.getParams().toArray())).intValue() ;
	}
	
	private SqlCondition getPageCondition(
			Map<String, ? extends Object> mapParams) {
		SqlCondition cond = new SqlCondition();
		return cond;
	}



}
